{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": [
    "def count_characters(input_string):\n",
    "    # 初始化计数器\n",
    "    letters = 0\n",
    "    spaces = 0\n",
    "    digits = 0\n",
    "    others = 0\n",
    "\n",
    "    # 遍历字符串中的每个字符\n",
    "    for char in input_string:\n",
    "        if char.isalpha():  # 如果是英文字母\n",
    "            letters += 1\n",
    "        elif char.isspace():  # 如果是空格\n",
    "            spaces += 1\n",
    "        elif char.isdigit():  # 如果是数字\n",
    "            digits += 1\n",
    "        else:  # 其他字符\n",
    "            others += 1\n",
    "\n",
    "    # 返回结果\n",
    "    return letters, spaces, digits, others\n",
    "\n",
    "# 从用户输入获取字符串\n",
    "input_string = input(\"请输入一行字符串: \")\n",
    "\n",
    "# 调用函数并获取结果\n",
    "letters, spaces, digits, others = count_characters(input_string)\n",
    "\n",
    "# 输出结果\n",
    "print(f\"英文字母个数: {letters}\")\n",
    "print(f\"空格个数: {spaces}\")\n",
    "print(f\"数字个数: {digits}\")\n",
    "print(f\"其他字符个数: {others}\")"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
